<template>
<section>
  <!--列表-->
  <el-table
      v-loading="symbolListLoading"
      :data="tableData"
      style="width: 100%">
    <el-table-column
        prop="symbol"
        :label="$t('message.pair')">
    </el-table-column>
    <el-table-column
        prop="type"
        :label="$t('message.type')">
      <template slot-scope="scope">
        <span>{{scope.row.type === '1' ? $t('message.major-coin') : $t('message.rare-coin')}}</span>
      </template>
    </el-table-column>
    <el-table-column
        prop="to_exchange"
        :label="$t('message.connected-exchange')">
    </el-table-column>
    <el-table-column
        prop="detail"
        :label="$t('message.operation')">
              <template slot-scope="scope">
                  <el-button @click="openDetail({symbol: scope.row.symbol})" type="text" size="small">{{$t('message.detail')}}</el-button>
              </template>
    </el-table-column>
  </el-table>

  <!--详情界面-->
      <el-dialog
              :title="$t('message.basic-information')"
              :visible.sync="detailVisible">
          <div class="dataTitle">{{$t('message.pair-name')}}&nbsp;&nbsp;&nbsp;&nbsp;<span>{{detailData.name}}</span></div>
          <table class="detailTable" border="1" v-loading="symbolDetailLoading">
              <tr>
                  <td>{{$t('message.pair-name')}}</td>
                  <td>{{detailData.symbol}}</td>
                  <td>{{$t('message.type')}}</td>
                  <td>{{detailData.type === '1' ? $t('message.major-coin') : $t('message.rare-coin')}}</td>
              </tr>
              <tr>
                  <td>{{$t('message.connected-exchange')}}</td>
                  <td>{{detailData.to_exchange}}</td>
                  <td>{{$t('message.data-sources')}}</td>
                  <td>{{detailData.to_symbol}}</td>
              </tr>
              <tr>
                  <td>{{$t('message.robot')}}</td>
                  <td>{{detailData.robot_id}}</td>
                  <td></td>
                  <td></td>
              </tr>
          </table>
          <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="detailVisible = false">{{$t('message.close')}}</el-button>
          </span>
      </el-dialog>
</section>
</template>

<script>
import { addedSymbolList, symbolDetail } from '../api/api'
// import axios from 'axios'
export default {
  data () {
    return {
      tableData: [
        {
          symbol: '',
          type: '',
          to_exchange: ''
        }
      ],
      detailVisible: false,
      detailVisible2: false,
      detailData: {
        robot_id: '',
        symbol: '',
        to_exchange: '',
        to_symbol: '',
        type: ''
      },
      detailData2: [],
      symbolListLoading: true,
      symbolDetailLoading: true
    }
  },
  beforeCreate () {
    console.log(111)
    addedSymbolList().then((res) => {
      this.tableData = res.data.symbols
      this.symbolListLoading = false
    }).catch((res) => {
      console.log(res)
    })
  },
  methods: {
    openDetail (data) {
      console.log(data)
      this.detailVisible = true
      symbolDetail(data).then((res) => {
        console.log(res)
        this.detailData = res.data.symbol
        this.symbolDetailLoading = false
      })
    }
  }
}

</script>

<style scoped lang="scss">
.dataTitle {
    width: 600px;
    margin: auto;
    padding: 10px 0 20px 0;
    span {
        font-weight: bold;
        font-size: 16px;
    }
}
.detailTable {
    margin: auto;
    width: 601px;
    border-collapse:collapse;
    border: 1px solid #dfe6ec;
    tr {
        td {
            width: 150px;
            height: 40px;
            border: 1px solid #dfe6ec;
            padding: 0 5px;
            text-align: center;
        }
        td:nth-child(1), td:nth-child(3) {
            background: #eef1f6;
        }
    }
}
.el-table__body-wrapper {

}
</style>
